package com.qding.park.manager.app.queue.handle;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.alibaba.fastjson.JSONObject;
import com.qding.park.common.core.cache.service.CacheServiceFacade;
import com.qding.park.common.core.exceptions.BaseException;
import com.qding.park.common.core.exceptions.IExceptionHandle;
import com.qding.park.common.core.redis.JedisClient;
import com.qding.park.common.core.redis.SerializeUtils;
import com.qding.park.manager.facade.queue.service.BusinessFacade;
import com.qding.park.manager.facade.queue.service.EventWriteBack;
import com.qding.park.manager.pojo.TbReserve;
import com.qding.park.manager.pojo.queue.QueueMsg;

/**
 * @ClassName InviteTimeOutHandle
 * @Description TODO(代缴支付完成)
 * @author Administrator
 * @Date 2016年9月17日 下午4:04:55
 * @version 1.0.0
 */
@Component("teneratPayedHandle")
public class TeneratPayedHandle extends AbstractOrderHandle{
	
	private static final Log _log = LogFactory.getLog(TeneratPayedHandle.class);

	@Autowired
	private BusinessFacade  businessFacade;
	
	@Autowired
	private EventWriteBack  eventWriteBack;
	
	@Override
	void actualHandle(QueueMsg msg) throws BaseException {
		TbReserve tbReserve=null;
		JSONObject data = (JSONObject) msg.getData();
		 tbReserve=SerializeUtils.unSerialize(data.toJSONString(), TbReserve.class);
		 businessFacade.teneratPayed(tbReserve);//通知车场
		 
		 eventWriteBack.temp_payed_Issued(tbReserve);//添加　mongodb数据
	}

	@Override
	boolean failDiscardRollBacK(QueueMsg msg) {
		_log.info("代缴支付完成回滚:"+msg);
		try {
			JSONObject data = (JSONObject) msg.getData();
			TbReserve tbReserve=SerializeUtils.unSerialize(data.toJSONString(), TbReserve.class);
			businessFacade.tempPayedIssuedFailRollBack(tbReserve);
			return true;
		} catch (Throwable e) {
			return false;
		}
	}

}
